define("pages/borrow/product", ["jquery", "widgets/widgets"],
function(a) {
	function b() {
		var a = e("#J_product-type"),
		b = e("#J_product-list>div"),
		c = e("#loanProductType"),
		d = e("#J_product-title"),
		f = "active",
		g = "hide",
		h = c.length && c.val();
		e("li", a).on("click",
		function() {
			e(this).siblings().removeClass(f).end().addClass(f),
			b.addClass(g).eq(e(this).index()).removeClass(g),
			d.text(" - " + e(this).find("span").text()),
			c.val(e(this).attr("data-type")).next().css("display", "none")
		}).each(function(a, c) {
			h && h.length && h == e(c).data("type") && (e(c).addClass(f), b.addClass(g).eq(a).removeClass(g))
		})
	}
	function c(a) {
		jQuery.validator.addMethod("isBorrowAmount",
		function(a, b) {
			return this.optional(b) || a >= parseInt(m[0], 10) && a <= parseInt(m[1], 10) && a % 50 === 0 && /^(([1-9]{1}\d*)|([0]{1}))?$/.test(a)
		},
		"借款金额范围" + m[0] + "-" + m[1] + "，且为50的倍数"),
		jQuery.validator.addMethod("isRateOver",
		function(a) {
			var b = parseFloat(Number(e("#minRate").html().replace("%", ""))),
			c = parseFloat(Number(e("#maxRate").html().replace("%", "")));
			return a = parseFloat(a),
			a >= b && c >= a
		},
		a.err.isRateOver)
	}
	function d() {
		var a = e("#borrowType"),
		b = e("#J_tip-borrowType"),
		c = "hide";
		return console.log("valiBorrwType", a.val().length),
		a.val().length ? (b.addClass(c), !0) : (b.removeClass(c), !1)
	}
	var e = a("jquery"),
	f = a("widgets/widgets"),
	g = f.Form,
	h = [],
	i = "hide";
	b(),
	e(".extra-div-a").on("mouseenter",
	function() {
		e(".ui-poptip-bx").removeClass(i);
		var a = e(".extra-div .extra-div-a").position().left;
		e(".extra-div .ui-poptip").css("left", a + 30)
	}),
	e(".extra-div-a").on("mouseleave",
	function() {
		e(".ui-poptip-bx").addClass(i)
	}),
	e("#borrowAmount").on("focus",
	function() {
		e("#J_amount_range").text("借款金额范围:3,000-500,000。且为50的倍数"),
		e("#J_borrowamount_pop").css("display", "block")
	}),
	e("#borrowAmount").on("blur",
	function() {
		e("#J_borrowamount_pop").css("display", "none")
	}),
	e("#apr").on("focus",
	function() {
		e("#J_yearrate_pop").css("display", "block")
	}),
	e("#apr").on("blur",
	function() {
		e("#J_yearrate_pop").css("display", "none")
	}),
	e(document).click(function(a) {
		var b = a.target;
		e(b).parent("span").hasClass("arrow") || e(b).parent("div").hasClass("J_select_btn") || e(".J_popBox").css("display", "none")
	}),
	e(".J_select_btn").click(function(a) {
		e(".J_popBox").css("display", "none");
		var b = e(a.currentTarget).parent().find("ul");
		"block" == b.css("display") ? b.css("display", "none") : b.css("display", "block")
	}),
	e(".J_popBox").delegate("li", "mouseover",
	function(a) {
		e(a.currentTarget).attr("class", "selected")
	}),
	e(".J_popBox").delegate("li", "mouseleave",
	function(a) {
		e(a.currentTarget).attr("class", "")
	}),
	e(".J_popBox").delegate("li", "click",
	function(a) {
		var b = e(a.currentTarget).attr("datavalue"),
		c = e(a.currentTarget).find("span").text(),
		d = e(a.currentTarget).parent().parent();
		if (d.find("input").val(b), d.find(".J_txt").text(c), ("RRGXD" == b || "RRSYD" == b || "RRWSD" == b) && (location.href = "/borrow/calculator.action?prodType=" + b), "repayTimeul" == e(a.currentTarget).parent("ul").attr("id")) switch (b) {
		case "3":
			e("#apr").val("10");
			break;
		case "6":
			e("#apr").val("11");
			break;
		case "9":
			e("#apr").val("12");
			break;
		case "12":
			e("#apr").val("12");
			break;
		case "15":
			e("#apr").val("13");
			break;
		case "18":
			e("#apr").val("13");
			break;
		case "24":
			e("#apr").val("13");
			break;
		case "36":
			e("#apr").val("13")
		}
		j(),
		l()
	}),
	e(".J_ui_checkbox").bind("click",
	function(a) {
		var b = e(a.currentTarget);
		b.hasClass("uncheck") ? (b.removeClass("uncheck"), b.addClass("check"), e("#agree_contract").attr("value", "true"), e("#J_error_agree").css("display", "none")) : (b.removeClass("check"), b.addClass("uncheck"), e("#agree_contract").attr("value", "false"), e("#J_error_agree").css("display", "block"))
	});
	var j = function() {
		var a, b, c, d = {},
		f = function(a) {
			return Number(a).toFixed(2)
		};
		a = e.trim(e("#borrowAmount").val()),
		c = e("#repayTime").val(),
		a && c && (d = {
			amount: a,
			apr: b,
			repayTime: c
		},
		e.ajax({
			url: "/borrow/getMonthlyInterest.action",
			data: e.param(d),
			type: "POST",
			dataType: "json",
			success: function(a) {
				e("#monthRepayMoney").html("￥" + f(a.monthlyRepay)),
				e("#managerFee").html("￥" + f(a.manageFee)),
				e("#monthRepayAccont").html("￥" + f(a.totalMonthlyRepay)),
				e("#guaranteeFee").html("￥" + f(a.guaranteeFee))
			}
		}))
	},
	k = function() {
		var a, b, c, d;
		b = e("#ratetable tr"),
		a = e.trim(e("#borrowAmount").val()),
		c = b.eq(1).find("td").filter(function() {
			return "服务费率" != e(this).text()
		}),
		d = b.eq(2).find("td").filter(function() {
			return "服务费" != e(this).text()
		}),
		!a || a % 50 !== 0 || a > 1e6 ? e.each(c,
		function(a) {
			d.eq(a).html("")
		}) : e.each(c,
		function(b) {
			var c = parseFloat(e(this).text().replace("%", ""));
			d.eq(b).html((c * a * .01).toFixed(0))
		})
	};
	e("#borrowAmount,#apr").keyup(function() {
		j(),
		l(),
		k()
	});
	var l = function() {
		for (var a = e("#productId").val(), b = e("#repayTime").val(), c = 0; c < h.length; c++) if (a == h[c].id) {
			for (var d = h[c].monthInte, f = 0, g = d.length; g > f; f++) b == d[f].month && (e("#minRate").html(d[f].minInterest + "%"), e("#maxRate").html(d[f].maxInterest + "%"));
			break
		}
	},
	m = e("#borrowAmount").data("range").split(","),
	n = g.validate({
		showTip: !0,
		tip: {
			borrowTitle: "不超过14字"
		},
		before: function(a) {
			c(a)
		}
	});
	e("#repayTimeul").each(function(a, b) {
		var c = e(b).parent(),
		d = e("#repayTime"),
		f = e(".J_txt", c),
		g = d && d.val();
		g.length || (g = 3, d.val(g)),
		e("li", b).each(function(a, b) {
			return e(b).attr("datavalue") == g ? void f.text(e(b).text()) : void 0
		}),
		j(),
		l(),
		k()
	}),
	e("form").submit(function() {
		var a = d();
		return n.valid() && a ? "true" != e("#agree_contract").attr("value") ? (e("#J_error_agree").css("display", "block"), !1) : (this.submit(), e(this).find(":submit").attr("disabled", "disabled"), !1) : !1
	})
});